/*
 * @Description: jishupu-admin-template
 * @Author: 技术铺<jishupu@qq.com>
 * @Date: 2021-11-17
 */
import { getCommonConfig } from '@/api/dictionary'
const state = {
  items: []
}

const mutations = {
  SET_DICTIONARY: (state, items) => {
    state.items = items
  }
}

const actions = {
  // 设置数据字典
  addConfig({ commit }) {
    return new Promise((resolve, reject) => {
      getCommonConfig().then(response => {
        const { items } = response.data
        commit('SET_DICTIONARY', items)
        resolve(items)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // 移除数据字典
  delConfig({ commit }) {
    return new Promise(resolve => {
      commit('SET_DICTIONARY', [])
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
